﻿using System;
using System.Collections.ObjectModel;

using Game.Common;
using Game.Common.Visitor;
using Game.ExtensibleObjects;

namespace Game.Map
{
    public interface IGameMap : IRuntimeExtensibleObject, IVisitorElement
    {
        event EventHandler<MapEventArgs> Dirty;

        int Width { get; }

        int Height { get; }

        bool IsDirty { get; set; }

        GameFieldCollection Fields { get; }

        ViewCollection Views { get; }

        GlobalItemCollection GlobalItems { get; }
    }

    public class GameMapEventArgs : EventArgs
    {
        public IMapFieldView MapField
        {
            get; set;
        }
    }
    
    public class MapEventArgs : EventArgs
    {
        readonly IGameMap _gameMap;
        
        public MapEventArgs(IGameMap map)
        {
            _gameMap = map;
        }
        
        public IGameMap GameMap
        {
            get { return _gameMap; }
        }
    }

    public class ViewCollection : KeyedCollection<GamePlayer, IGameMapView>
    {
        protected override GamePlayer GetKeyForItem(IGameMapView item)
        {
            return item.Owner;
        }
    }
    
}
